<?php
	class Login extends CI_Controller
	{
		function __construct()
		{
			parent::__construct();
			$this->load->model('crud_model');

		}

		function index()
		{
			$this->load->view('administrator/v_login');
		}

		function doLogin()
		{
			$username    = $this->input->post('username');
			$password = $this->input->post('password');

			$login_status = $this->access->login($username,$password);			

			if($login_status == TRUE)
			{
				$data["id"] = "";
				$data["user_id"] = $this->session->userdata('user_id');
				$data["datetime"] = gmdate('Y-m-d H:i:s', time()+60*60*7);
				$data["ip"] = $this->input->ip_address();

				$this->crud_model->save('access_log',$data);
				redirect('administrator/dashboard');
			}
			else
			{
				redirect('administrator/login');
			}

		}

		function logout()
		{
			$this->access->logout();
			redirect("administrator/login");
		}

	}
?>
